package com.yuanshi.food.controller.web;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuanshi.food.application.web.UserWebApplication;
import com.yuanshi.food.common.entity.Response;
import com.yuanshi.food.model.web.vo.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 *
 * @author wang
 * @date 2025/11/06
 */
@RestController
@RequestMapping("/api/${app.config.web-api-version}/user/")
public class UserController {

    @Resource
    private UserWebApplication userWebApplication;

    /**
     * 微信小程序登录接口
     * @param code 小程序登录 code（前端通过 wx.login() 获取）
     */
    @Operation(summary = "登录")
    @ApiOperationSupport(order = 1)
    @PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Response<LoginVO> login(@NotBlank(message = "code不能为空") @RequestParam String code) {
        return Response.success(userWebApplication.login(code));
    }
}